using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class LevelBar : MonoBehaviour
{
    public static LevelBar instance;

    public float moveTime;
    public RectTransform rectTransform;
    public int nowLevel;
    public List<float> positions;
    // Start is called before the first frame update
    void Start()
    {
        instance = this;

        nowLevel = 1;
        rectTransform.anchorMin = new Vector2(positions[0], 0);
        rectTransform.anchorMax = new Vector2(positions[0] + 0.0265f, 1);
    }

    public void nextLevel()
    {
        DOTween.To(
            () => rectTransform.anchorMin,
            x => rectTransform.anchorMin = x,
            new Vector2(positions[nowLevel], 0),
            moveTime
        ).SetEase(Ease.Linear);
        DOTween.To(
            () => rectTransform.anchorMax,
            x => rectTransform.anchorMax = x,
            new Vector2(positions[nowLevel] + 0.0265f, 1),
            moveTime
        ).SetEase(Ease.Linear);
        ++nowLevel;
        if(nowLevel == 10)
        {
            nowLevel = 0;
        }
    }
}
